from django.shortcuts import redirect


class BkMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response
        # One-time configuration and initialization.

    def __call__(self, request):
        # Code to be executed for each request before
        # the view (and later middleware) are called.

        response = self.get_response(request)
        path = request.path  # 获取当前路径
        if path not in ['/login/', '/register/', '/logout/', '/ok/', '/image/code/']:
            if 'bkuser' not in request.session:
                return redirect('/login/')
        # Code to be executed for each request/response after
        # the view is called.

        return response
